package com.hancheng.usercloud.feign.controller;

import com.hancheng.commoncloud.framework.annotation.PassToken;
import com.hancheng.commoncloud.framework.result.Response;
import com.hancheng.usercloud.business.entity.dto.UserIdDTO;
import com.hancheng.usercloud.business.entity.dto.UserInsertTestDTO;
import com.hancheng.usercloud.business.entity.vo.UserVO;
import com.hancheng.usercloud.business.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "用户消息表（远程调用内部接口）")
@RestController
@RequestMapping("/api/user/feign")
public class UserFeignController {
    @Autowired
    private SysUserService sysUserService;

    /**
     * 根据用户ID获取用户信息
     *
     * @param userIdDTO
     * @return
     */
    @PassToken
    @ApiOperation(value = "根据用户ID获取用户信息", httpMethod = "POST")
    @PostMapping("/getUserVOByUserId")
    public Response<UserVO> getUserVOByUserId(@RequestBody @Valid UserIdDTO userIdDTO) {
        return Response.ok(sysUserService.getUserVOByUserId(userIdDTO));
    }

    /**
     * 新增用户（测试seata）
     *
     * @param userInsertTestDTO
     * @return
     */
    @ApiOperation(value = "新增用户（测试seata）", httpMethod = "POST")
    @PostMapping("/insertTest")
    Response<Void> insertTest(@RequestBody UserInsertTestDTO userInsertTestDTO){
        sysUserService.insertTest(userInsertTestDTO);
        return Response.ok();
    }
}
